package c.e.a.b.b.h;

import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.Message;
import c.e.a.b.b.h.c.a;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

public final class n implements ServiceConnection {
    public final Set<ServiceConnection> a = new HashSet();
    public int b = 2;
    public boolean c;
    public IBinder d;
    public final a e;
    public ComponentName f;
    public final /* synthetic */ m g;

    public n(m mVar, a aVar) {
        this.g = mVar;
        this.e = aVar;
    }

    public final void a(String str) {
        this.b = 3;
        m mVar = this.g;
        boolean b = mVar.f.b(mVar.d, this.e.a(), this, this.e.c);
        this.c = b;
        if (b) {
            Message obtainMessage = this.g.e.obtainMessage(1, this.e);
            m mVar2 = this.g;
            mVar2.e.sendMessageDelayed(obtainMessage, mVar2.h);
            return;
        }
        this.b = 2;
        try {
            mVar = this.g;
            c.e.a.b.b.i.a aVar = mVar.f;
            Context context = mVar.d;
            Objects.requireNonNull(aVar);
            context.unbindService(this);
        } catch (IllegalArgumentException unused) {
        }
    }

    public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
        synchronized (this.g.c) {
            this.g.e.removeMessages(1, this.e);
            this.d = iBinder;
            this.f = componentName;
            for (ServiceConnection onServiceConnected : this.a) {
                onServiceConnected.onServiceConnected(componentName, iBinder);
            }
            this.b = 1;
        }
    }

    public final void onServiceDisconnected(ComponentName componentName) {
        synchronized (this.g.c) {
            this.g.e.removeMessages(1, this.e);
            this.d = null;
            this.f = componentName;
            for (ServiceConnection onServiceDisconnected : this.a) {
                onServiceDisconnected.onServiceDisconnected(componentName);
            }
            this.b = 2;
        }
    }
}
